var crypto = require('crypto'),
    User = require('../models/user.js'),
    Post = require('../models/post.js');
var Comment = require('../models/comment.js');
var http = require('http');

module.exports = function(app){

  app.get('/',function(req,res){
    var pageNo = req.query.pn ? parseInt(req.query.pn) : 1,
        pageSize = req.query.ps ? parseInt(req.query.ps) : 10;
    Post.getTen(null,pageNo,pageSize,function(err,posts,total){
      if(err){
        posts = [];
      }
      res.render('index',{
        title:'主页',
        user: req.session.user,
        posts: posts,
        pageNo: pageNo,
        pageSize: pageSize,
        isFirstPage: (pageNo - 1) == 0,
        isLastPage: ((pageNo - 1)*pageSize + posts.length) == total,
        success: req.flash('success').toString(),
        error: req.flash('error').toString()
      });
    });
  });

  app.get('/redis',function(req,res) {
    res.render('redis',{
      title:'监听redis',
      //user: req.session.user,
      //success: req.flash('success').toString(),
      //error: req.flash('error').toString()
    });
  })

  //一定要放在所有的请求的最后边
  app.use(function (req, res) {
    res.render("404");
  });

};
